import { ref } from 'vue'
import  {useLayout,type AppContext} from '.'
import {onLoad} from '@dcloudio/uni-app'
import { getPageInfo, } from '@/common/request/api'

export const useLayoutPage = (ctx:AppContext,isHome = false) => {
	const loading = ref(false)
	const {componentsList,pageStyle,mpShare,setPageBackgroundImage,advertisingSetting,setPageOption} = useLayout(ctx)

	let layoutPageParams = {}

	onLoad((opt) => {
		layoutPageParams = opt || {}
	})

	const init = (id: string | number) => {
		getPageInfo(id).then(res => {
			setPageOption(res.data,false,layoutPageParams)
		}).finally(() => {
			loading.value = false
		})
	}

	return {
		loading,
		componentsList,
		pageStyle,
		setPageBackgroundImage,
		layoutPageParams,
		advertisingSetting,
		init,
		mpShare
	}
}